package com.guo.pet_store.admin.dao;

import com.guo.pet_store.admin.pojo.Pet;
import com.guo.pet_store.admin.pojo.PetQuery;
import com.guo.pet_store.admin.pojo.ShopCar;
import com.guo.pet_store.admin.pojo.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


public interface ShopCarRepository extends JpaRepository<ShopCar,Long> {

    @Transactional
    @Modifying
    @Query(nativeQuery = true,value = "INSERT INTO pet_shop_car(pet_id,shop_car_id) values (?1,?2)")
    int shopCarAddItem(Long petId,Long carId);


    @Transactional
    @Modifying
    @Query(nativeQuery = true,value = "delete from pet_shop_car where pet_id = ?1 and shop_car_id = ?2")
    void deleteACarItem(Long petId,Long carId);

    @Transactional
    @Modifying
    @Query(nativeQuery = true,value = "insert into shopcar (user_id) values (?1)")
    void connectToUser(Long userId);

    ShopCar findShopCarByUser(User user);

    @Transactional
    @Modifying
    @Query(nativeQuery = true,value = "delete from pet_shop_car where shop_car_id = ?1")
    void clearCar(Long carId);



}
